package cn.edu.aynu.service.impl;

/**
 * 带分页条件查询用户
 * @author home
 *
 */
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.edu.aynu.mapper.MyCustomerDao;
import cn.edu.aynu.pojo.Customer;
import cn.edu.aynu.pojo.QueryVo;
import cn.edu.aynu.service.CustomerService;
import cn.edu.aynu.utils.Page;

@Transactional
@Service
public class CustomerServiceImpl implements CustomerService
{
    @Autowired
    private MyCustomerDao myCustomerDao;
    
    // 通过四个条件 查询分页对象
    @Override
    public Page<Customer> selectPageByQueryVo(QueryVo vo)
    {
        Page<Customer> page = new Page<>();
        // 显示页码总数目 页码数=总记录数/设置的数字
        page.setSize(vo.getSize());
        // 判断当前页
        if (null != vo.getPage())
        {
            page.setPage(vo.getPage());
            vo.setStartRow((vo.getPage() - 1) * vo.getSize());
        }
        vo.setCustName(vo.getCustName());
        vo.setCustSource(vo.getCustSource());
        vo.setCustIndustry(vo.getCustIndustry());
        vo.setCustLevel(vo.getCustLevel());
        // 总条数
        page.setTotal(myCustomerDao.customerCountByQueryVo(vo));
        page.setRows(myCustomerDao.selectCustomerListByQueryVo(vo));
        return page;
        
    }
    
    /*
     * 通过ID查询用户
     * 
     * @see com.ccc.crm.service.CustomerService#selectCustomerById(java.lang.Integer)
     */
    @Override
    public Customer selectCustomerById(Integer id)
    {
        return myCustomerDao.selectCustomerById(id);
    }
    
    // 通过ID修改客户
    @Override
    public void updateCustomerById(Customer customer)
    {
        myCustomerDao.updateCustomerById(customer);
    }
    
    // 通过ID删除客户
    @Override
    public void deleteCustomerById(Integer id)
    {
        myCustomerDao.deleteCustomerById(id);
    }
    
    @Override
    public void createCustomer(Customer customer)
    {
        myCustomerDao.createCustomer(customer);
    }
    
}
